<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
    import { getGroupQTCount } from '@/api/case/statisticalChart'
import echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import resize from './mixins/resize'

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '300px'
    }
  },
  data() {
    return {
        chart: null,
        //延期、缓办、挂起案件在全部案件中占比
        Data:[],
        tipsData:[],
    }
  },
  mounted() {
      //获取接线员-----延期、缓办、挂起案件在全部案件中占比
      this.getGroupQTCount();
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
      //获取接线员-----延期、缓办、挂起案件在全部案件中占比
      getGroupQTCount(){
          this.chart = null;
          getGroupQTCount().then(
              (res) =>{
                  this.Data = res.data;
                  for(let i= 0;i<res.data.length;i++){
                      this.tipsData.push(res.data[i].name);
                  }
                  this.$nextTick(()=>{
                      this.initChart();
                  })
              }
          ).catch((error) => {
              console.log(error, 'getGroupQTCount');
          })
      },
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')

      this.chart.setOption({
          title: {
              text: '延期、缓办、挂起案件在全部案件中占比',
              textStyle:{
                  color: '#6b6b6b',
                  fontSize: 15,
                  fontWeight: 'normal'
              },
              left: 'center'
          },
        tooltip: {
          trigger: 'item',
          formatter: '{a} <br/>{b} : {c} ({d}%)'
        },
        legend: {
          left: 'center',
          bottom: '10',
          data: this.tipsData
        },
        series: [
          {
            name: '',
            type: 'pie',
            roseType: 'radius',
            radius: [15, 85],
            center: ['50%', '48%'],
            data: this.Data,
            animationEasing: 'cubicInOut',
            animationDuration: 2600
          }
        ]
      })
    }
  }
}
</script>
